from django.shortcuts import render
from django.views import View

from apps.contents.models import ContentCategory
from apps.contents.utils import get_categories


class IndexView(View):
    """首页广告"""

    def get(self, request):
        """提供首页广告界面"""
        #分类数据
        categories = get_categories()

        #广告数据
        contents = {}
        #1.获取所有数据
        content_categories = ContentCategory.objects.all()
        for cat in content_categories:
            contents[cat.key]=cat.content_set.filter(status=True).order_by('sequence')

        return render(request, 'index.html',context={'categories':categories,
                                                     'contents':contents})

